from concurrent.futures.thread import ThreadPoolExecutor

from sqlalchemy.orm import Session,query
import sqlalchemy
import loadLog
import ticket_base
import sqlalchemy_client
from threading import Thread

import time

log = loadLog.LoadLog()
log.info('xxxxxxxx')

if __name__ == '__main__':
    tt = ticket_base.get_chehao_info()
    config = {

            'mode': '连接池',
            # 'mode': "ODBC",
            'type': 'MYsql',
            'name': 'ics',
            'host': '127.0.0.1',
            'dsn': 'MSSQL',
            'mincached': 10,
            # 'port': 3306,
            'username': 'ics',
            'password': '123456',
            'database': 'test',
            'databasepath': r'D:\CODE\PYTHON\DA_V5\app_all\config.db'
            # 'charset': 'gbk'
            }
    app = sqlalchemy_client.Connect(config)
    # res = app.execSql("insert into t_540_chehao (f_id,f_chehao)values (1234,777777)")
    # print(res)

    pool = ThreadPoolExecutor(max_workers = 10)


    def work(app, mode = 0,i=0):
        sql = "SELECT * FROM T_540_CHEHAO"
        if mode == 0:
            result = app.loadSql(sql, 0,1)
            info ="序号：{}的线程，模式：{}，查询到数据：{}\n".format(i,mode,result)
            print(info)
            return result.filter(sqlalchemy_client.text('F_ID=12'))
        conn= app.engine.connect()
        # result =conn.query( tt).all()
        result =conn.execute(sql)
        info ="序号：{}的线程，模式：{}，查询到数据：{}\n".format(i,mode,result)
        print(info)
        conn.close()
        return list(result)

    n=0
    while True:
        n+=1
        print("发送：{}，次".format(n))
        for i in range(20):
            res=pool.submit(work, app, 0,i)
            print(1111111,res.result())
            # print("线程：",i+1,int(time.time()))


        time.sleep(5)